package com.pig.graduate.controller.material;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig.graduate.domain.event.EventEntry;
import com.pig.graduate.domain.material.MaterialSupplier;
import com.pig.graduate.domain.sys.SysBuildings;
import com.pig.graduate.domain.sys.SysUser;
import com.pig.graduate.result.MyResult;
import com.pig.graduate.service.event.EventEntryService;
import com.pig.graduate.service.material.MaterialSupplierService;
import com.pig.graduate.service.sys.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = {"供应商"}, description = "供应商")
@RestController
@RequestMapping("/material/supplier")
public class MaterialSupplierController {

    @Autowired
    private MaterialSupplierService materialSupplierService;

    /**
     * 进场记录
     * @param materialSupplier
     * @return
     */
    @ApiOperation(value = "供应商列表",notes = "供应商列表")
    @PostMapping("/list")
    public MyResult supplierList(@RequestBody MaterialSupplier materialSupplier){
        Page<MaterialSupplier> sysBuildingsPage = new Page<>(materialSupplier.getPageNum(),materialSupplier.getPageSize());
        Page<MaterialSupplier> page = new LambdaQueryChainWrapper<MaterialSupplier>(materialSupplierService.getBaseMapper())
                .like(MaterialSupplier::getName, materialSupplier.getName())
                .like(MaterialSupplier::getAddress, materialSupplier.getAddress())
                .page(sysBuildingsPage);
        return MyResult.success(page);
    }

    @ApiOperation(value = "供应商新增修改",notes = "供应商新增修改")
    @PostMapping("/addAndUpdate")
    public MyResult addAndUpdateSupplier(@RequestBody MaterialSupplier materialSupplier){
        materialSupplierService.saveOrUpdate(materialSupplier);
        return MyResult.success();
    }

    @ApiOperation(value = "供应商删除",notes = "供应商删除")
    @PostMapping("/delete")
    public MyResult deleteSupplier(@RequestBody List<Long> ids){
        materialSupplierService.removeByIds(ids);
        return MyResult.success();
    }


}
